﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Text;

namespace vuonthieunhi.Library
{
    public class Constants
    {
        public const string UPLOAD_VITUAL_IMAGE_PATH = "/FileUpload/Images/Partner/";
        public const string UPLOAD_VITUAL_MANUFACTURER_PATH = "/FileUpload/Images/Manufacturer/";
        public const string ORDER_COOKIE = "p@ssw0rddst3@m304";
        public const string SORT_COLUMN = "sidx";
        public const string SORT_ORDER = "sord";
        public const string PAGE_INDEX = "page";
        public const string ROW_COUNT = "rows";
        public const string UPLOAD_ADV_ = "/FileUpload/";
        public const string UPLOAD_ADV_IMAGE_PATH = "/FileUpload/Images/Advertising/";
        public const string UPLOAD_CATEGORY_PATH = "/Themes/images/";
        public const string DATETIME_FORMAT = "dd/MM/yyyy";
        public const string UPLOAD_TEMP_PATH = "/FileUpload/TempUpload/";
        public const string UPLOAD_IMAGE_PATH = "/FileUpload/Images/News";
        public const string UPLOAD_BANNER_IMAGE_PATH = "/FileUpload/Images/BigPartnerBanner/";
        public const string UPLOAD_FCK_FLASH_PATH = "/FileUpload/Images/FCK/Flash/";
        public const string UPLOAD_FCK_IMG_PATH = "/FileUpload/Images/FCK/img/";
        public const string PHOTO_PATH_ROOT_PARTNER = "/FileUpload/Images/Partner/";
        public const string UPLOAD_PHOTO_SUCCESS = "Upload Hình Ảnh Thành Công.";
        public const string NO_IMAGE = "NoImage.jpg";
        public static readonly string UPLOAD_ALLOW_EXT = ConfigurationManager.AppSettings["allow_ext"];
        public static readonly string UPLOAD_ALLOW_IMG_EXT = ConfigurationManager.AppSettings["allow_img_ext"];
        public static readonly string UPLOAD_ALLOW_FLASH_EXT = ConfigurationManager.AppSettings["allow_flv_ext"];
        public static readonly int UPLOAD_FILE_SIZE = int.Parse(ConfigurationManager.AppSettings["maximum_file_size"]);
        //Category
        public const string CATEGORY_FIRST_ITEM = "Chọn loại sản phẩm";
        public const string PARENT_CATEGORY_FIRST_ITEM = "-Chọn danh mục cha-";
        public const string CATEGORY_FIRST_DISTRICT = "Chọn Quận/Huyện";
        public const string CATEGORY_FIRST_PROVINCE = "Chọn Tỉnh/Thành";
        public const string PARTNER_DEFAULT_VALUE = "Partner";
        public const string CATEGORY_DEFAULT_VALUE = "Category";
        public const string PROMOTION_DEFAULT_VALUE = "Promotion";
        public const string PHOTO_PATH_ROOT_CATEGORY = "/FileUpload/Images/Category/";
        public static int ConvertToInt(object value)
        {
            return (value != null && IsNaturalNumber(value.ToString())) ? int.Parse(value.ToString()) : 0;
        }
        public static bool IsNaturalNumber(String strNumber)
        {
            Regex objNotNaturalPattern = new Regex("[^0-9]");
            Regex objNaturalPattern = new Regex("0*[1-9][0-9]*");

            return !objNotNaturalPattern.IsMatch(strNumber) && objNaturalPattern.IsMatch(strNumber);
        }
        public static double ConvertToDouble(object value)
        {
            return (value != null && IsNaturalNumber(value.ToString())) ? double.Parse(value.ToString()) : 0;
        }

        public static string ButtonEdit(string actionUrl)
        {
            return "<input type=\"button\" class=\"icon edit\" title=\"Cập nhật\" onclick=\"window.location = '" + actionUrl + "'\" />";
        }
        public static string ButtonEditPopup(string actionUrl, string title, int width)
        {
            string onclick = string.Format("JS_LIB.popup('{0}','{1}',{2});", actionUrl, title, width);
            return "<input type=\"button\" class=\"icon edit\" title=\"Cập nhật\" onclick=\"" + onclick + "\" />";
        }
        public static string Link(string id, string actionUrl, string display, bool haveTooltip)
        {
            if (haveTooltip)
            {
                return "<a id=" + id + " class='showTooltip' href='" + actionUrl + "'>" + display + "</a>";
            }
            else
            {
                return "<a id=" + id + "  href='" + actionUrl + "'>" + display + "</a>";
            }
        }

        public static string Button(string css, string title, string action)
        {
            return "<input type='button' class='icon " + css + "' title='" + title + "' onclick=\"" + action + "\" />&nbsp;";
        }

        public static string encryptDataMd5(string data, int length)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] hashedBytes;
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
            StringBuilder sbuilder = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                sbuilder.Append(hashedBytes[i].ToString("x2"));
            }
            return sbuilder.ToString();
        }
        public const string SERVER_COOKIE = "p@ssw0rddst3@m"; 
        public static string SetHtmlForCKEditor(string original)
        {
            if (string.IsNullOrEmpty(original))
            {
                return string.Empty;
            }
            else
            {
                original = original.Replace("&lt;", "<");
                original = original.Replace("&gt;", ">");
            }
            return original;
        }

        public static string ShowActiveImage(object obj)
        {
            string str = "<span class=\"{0}\"></span>";
            return string.Format(str, (obj != null && (bool)obj) ? "iactive" : "iinactive");
        }
        public const string UNIQUE_TIME = "HH_mm_ss_ffff";
    }
}